import { View } from "../../../mvc/core/View";
import { ILayOut } from "../../../../modules/interfaces/ILayOut";
import { LayerManager } from "../../manager/LayerManager";
import { ObjCreate } from "../common/ObjCreate";
import { SecTimer } from "../../../../com/gengine/core/frame/SecTimer";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { Language } from "../../../../extend/language/Language";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { DataEvent } from "../../events/DataEvent";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { Global } from "../../../../com/gengine/global/Global";
//class GangFightsWaitingTimeView
    
    export  class GangFightsWaitingTimeView extends View implements ILayOut
    {
        constructor()
        {
            super();
            layer = LayerManager.msgTipLayer;
            this.resetPosition();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this.mouseEnabled = false;
            this.mouseChildren = false;
            ObjCreate.createBg(0, 0, 300, 45, this, "ToolTipBg");
            this._secTimer = new SecTimer();
            var loc1=new GTextFormat(FontUtil.songtiName, 12, 15788607);
            loc1.bold = true;
            this._tfWait = ObjCreate.createTextField("", 30, 15, 270, 22, this, loc1);
            this._tfWait.htmlText = Language.getStringByParam(42251, "0");
            Dispatcher.addEventListener(EventName.StageResize, this.onStageResize);
            return;
        }

        /* internal  */onStageResize(arg1: DataEvent): void
        {
            this.resetPosition();
            return;
        }

        public start(): void
        {
            this._secTimer.start();
            this._secTimer.addListener(TimerType.ENTERFRAME, this.onTimeChange);
            return;
        }

        /* internal  */onTimeChange(arg1: SecTimer): void
        {
            this._tfWait.htmlText = Language.getStringByParam(42251, this._secTimer.currentCount.toString());
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this._tfWait.htmlText = Language.getStringByParam(42251, "0");
            return;
        }

        public reset(): void
        {
            this._secTimer.reset();
            return;
        }

        public stop(): void
        {
            this._secTimer.stop();
            return;
        }

        public resetPosition(): void
        {
            this.x = (Global.stage.stageWidth - 300) / 2;
            this.y = 90;
            return;
        }

        public static get instance(): GangFightsWaitingTimeView
        {
            if (!GangFightsWaitingTimeView._instance) 
            {
                GangFightsWaitingTimeView._instance = new GangFightsWaitingTimeView();
            }
            return GangFightsWaitingTimeView._instance;
        }

        public static hasInstance(): Boolean
        {
            return !(GangFightsWaitingTimeView._instance == null);
        }

        /* internal */ /* var */_secTimer: SecTimer;

        /* internal */ /* var */_tfWait: Object /* flash.text.TextField */;

        /* internal */ static /* var */_instance: GangFightsWaitingTimeView;
    }
